﻿
@{
	Layout = null;
}

<style>
	#dv_opedit {
		position: fixed;
		top: 19%;
		right: 10px;
	}

	.dv-left {
		width: 900px;
		float: left;
	}

	.dv-left-tb {
		/*overflow-y: auto;*/
		border-radius: 5px;
		background: #ffffff;
		border: 5px double #a6e6a5;
	}

	#sscz {
		float: left;
		background-color: #a6e6a5;
		height: 100px;
		padding: 10px;
		color: #645a5a;
		border-radius: 5px;
	}
</style>


<div id="dv_opedit">
	<a class="btn  " id="sscz">手<br />术<br />管<br />理<br /><span class="glyphicon glyphicon-edit"></span></a>
	<div class="dv-left">
		<div class="dv-left-tb" id="tb_opedit" style="padding-top:10px;height:423px;">
			<div><input type="hidden" id="op_rowid" name="op_rowid" /></div>
			<table class="form" style="width:95%;">
				<tr>
					<th class="formTitle "><span class="required">*</span>是否急诊手术：</th>
					<td class="formValue">
						<select id="SSLX" name="SSLX" class="form-control ">
							<option value=""> 请选择 </option>
							<option value="1">是</option>
							<option value="0">否</option>
						</select>
					</td>
					<th class="formTitle "><span class="required">*</span>手术及操作：</th>
					<td class="formValue">
						<input id="op_ssdm" name="op_ssdm" class="form-control required" attr-ssdm="" attr-ssjb="" autocomplete="off" />
					</td>
					<th class="formTitle ">@*<span class="required">*</span>*@手术级别：</th>
					<td class="formValue">
						<select id="SSJB" name="SSJB" class="form-control ">
							<option value=""> 请选择 </option>
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
							<option value="4">4</option>
						</select>
					</td>
				</tr>
				<tr>
					<th class="formTitle "><span class="required">*</span>手术及操作日期：</th>
						<td class="formValue">
							<input id="op_ssrq" type="text" class="form-control input-wdatepicker formClearIgnore required" value="" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss'})" />
						</td>
					<th class="formTitle ">@*<span class="required">*</span>*@手术开始日期：</th>
					<td class="formValue">
						<input id="SSKSSJ" type="text" class="form-control input-wdatepicker formClearIgnore required" value="" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss'})" />
					</td>
					<th class="formTitle ">@*<span class="required">*</span>*@手术结束日期：</th>
					<td class="formValue">
						<input id="SSJSSJ" type="text" class="form-control input-wdatepicker formClearIgnore required" value="" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss'})" />
					</td>
				</tr>
				<tr>
					<th class="formTitle "><span class="required">*</span>主刀医生：</th>
					<td class="formValue">
						<input id="op_zdys" name="op_zdys" class="form-control" />
					</td>
					<th class="formTitle ">I助：</th>
					<td class="formValue">
						<input id="op_sszl1" name="op_sszl1" class="form-control " />
					</td>
					<th class="formTitle ">II助：</th>
					<td class="formValue">
						<input id="op_sszl2" name="op_sszl2" class="form-control" />
					</td>
				</tr>
				<tr>
					<th class="formTitle ">术前准备天数</th>
					<td class="formValue">
						<input id="SQZBSJT" name="SQZBSJT" class="form-control " />
					</td>
					<th class="formTitle ">术前预防性<br />抗菌药物给药时间：</th>
					<td class="formValue">
						<input id="SQYFKJGYS" type="text" class="form-control input-wdatepicker formClearIgnore required" value="" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss'})" />
					</td>
				</tr>
				<tr>
					<th class="formTitle ">麻醉医生：</th>
					<td class="formValue">
						<input id="op_mzys" name="op_mzys" class="form-control " />
					</td>

					<th class="formTitle ">麻醉方式：</th>
					<td class="formValue">
						<select id="op_mzfs" name="op_mzfs" class="form-control ">
							<option>请选择</option>
						</select>
					</td>
					<th class="formTitle ">ASA麻醉分级：</th>
					<td class="formValue">
						<select id="MZFJ_ASA" name="MZFJ_ASA" class="form-control ">
							<option value="">请选择</option>
							<option value="Ⅰ">Ⅰ</option>
							<option value="Ⅱ">Ⅱ</option>
							<option value="Ⅲ">Ⅲ</option>
							<option value="Ⅳ">Ⅳ</option>
							<option value="Ⅴ">Ⅴ</option>
						</select>
					</td>

				</tr>
				<tr>
					<th class="formTitle ">麻醉开始时间：</th>
					<td class="formValue">
						<input id="MZKSSJNYR" type="text" class="form-control input-wdatepicker formClearIgnore required" value="" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss'})" />
					</td>
				</tr>
				<tr>
					<th class="formTitle ">切口部位	：</th>
					<td class="formValue">
						<input id="QKBW" name="QKBW" class="form-control " />
					</td>
					<th class="formTitle ">切口愈合等级：</th>
					<td class="formValue">
						<select id="op_yhdj" name="op_yhdj" class="form-control ">
							<option>请选择</option>
						</select>
					</td>
					<th class="formTitle ">切口愈合类别：</th>
					<td class="formValue">
						<select id="op_yhlb" name="op_yhlb" class="form-control ">
							<option>请选择</option>
						</select>
					</td>
				</tr>
				<tr>
					<th class="formTitle ">手术切口感染	：</th>
					<td class="formValue">
						<select id="SSQKGR" name="SSQKGR" class="form-control ">
							<option value="">请选择</option>
							<option value="1">有</option>
							<option value="2">无</option>
						</select>
					</td>
					<th class="formTitle ">手术并发症：</th>
					<td class="formValue">
						<select id="SSBFZ" name="SSBFZ" class="form-control">
							<option value="">请选择</option>
							<option value="1">有</option>
							<option value="2">无</option>
						</select>
					</td>
				</tr>

				<tr>
					<th class="formTitle ">手术并发症名称：</th>
					<td class="formValue"><input name="SSBFZMC" type="checkbox" value="伤口裂开、出血或血肿" id="id1"><label>伤口裂开、出血或血肿</label></td>

					<td class="formValue">
						<input name="SSBFZMC" type="checkbox" value="呼吸衰竭" id="id2">
						<label>呼吸衰竭</label>
					</td>

					<td class="formValue">
						<input name="SSBFZMC" type="checkbox" value="医源性气胸" id="id3"><label>医源性气胸</label>
					</td>
					<td class="formValue">
						<input name="SSBFZMC" type="checkbox" value="髋关节骨折" id="id4">
						<label>髋关节骨折</label>
					</td>
					<td class="formValue">
						<input name="SSBFZMC" type="checkbox" value="生理与代谢紊乱" id="id5">
						<label>生理与代谢紊乱</label>
					</td>
				</tr>
				<tr>
					<th></th>
					<td class="formValue">
						<input name="SSBFZMC" type="checkbox" value="手术过程中异物遗留" id="id6"><label>手术过程中异物遗留</label>
					</td>
					<td class="formValue">
						<input name="SSBFZMC" type="checkbox" value="肺栓塞" id="id7">
						<label>肺栓塞</label>
					</td>
					<td class="formValue"><input name="SSBFZMC" type="checkbox" value="肺部感染" id="id8"><label>肺部感染</label></td>
					<td class="formValue">
						<input name="SSBFZMC" type="checkbox" value="深静脉血栓" id="id9">
						<label>深静脉血栓</label>
					</td>
				</tr>
				<tr>
					<th></th>
					<td class="formValue"><input name="SSBFZMC" type="checkbox" value="医源性意外穿刺伤" id="id10"><label>医源性意外穿刺伤</label></td>
					<td class="formValue"><input name="SSBFZMC" type="checkbox" value="医源性撕裂伤" id="id11"><label>医源性撕裂伤</label></td>
					<td class="formValue">
						<input name="SSBFZMC" type="checkbox" value="败血症" id="id12">
						<label>败血症</label>
					</td>
					<td class="formValue">
						<input name="SSBFZMC" type="checkbox" value="其他" id="id13">
						<label>其他</label>
					</td>

				</tr>
				<tr>
					<td></td>
					<td></td>
					<td colspan="2">
						<input id="btn_submit_op" type="button" class="btn btn-default" value="保存" style="width:50px;background-color:#9cf7cc;float:right;margin-right:10px;" />
						<input id="btn_del_op" type="button" class="btn btn-default" value="删除" style="width:50px;background-color:#9cf7cc;float:right;margin-right:10px;" />
						<input id="btn_reset_op" type="button" class="btn btn-default" value="重置" style="width:50px;background-color:#9cf7cc;float:right;margin-right:10px;" />
					</td>
				</tr>
			</table>
		</div>
	</div>
</div>



<script type="text/javascript">
	var opdata = {};
	var check_val = "";
	function getopdata() {
		var QKYHDJ_val
		var op_yhdj_val = $("#op_yhdj option:selected").text();
		var op_yhlb_val = $("#op_yhlb option:selected").text()
		if (op_yhdj_val == "请选择" && op_yhlb_val == "请选择") {
			QKYHDJ_val = '';
		} else {
			QKYHDJ_val = $("#op_yhdj option:selected").text() + "/" + $("#op_yhlb option:selected").text()
		}
		opdata = {
			BAH: $("#BAH").val(),
			ZYH: $("#ZYH").val(),
			SSJCZBM: $("#op_ssdm").attr("attr-ssdm"),
            SSJCZRQ: $("#op_ssrq").val(),
			SSJB: $("#SSJB").val(),
			SSJCZMC: $("#op_ssdm").val(),
			SZ: $("#op_zdys").attr("data-StaffGh"),
			SZMC: $("#op_zdys").val(),
			YZ: $("#op_sszl1").attr("data-StaffGh"),
			YZMC: $("#op_sszl1").val(),
			EZ: $("#op_sszl2").attr("data-StaffGh"),
			EZMC: $("#op_sszl2").val(),
			QKDJ: $("#op_yhdj").val(),
			MZFS: $("#op_mzfs").val(),
			MZFSMS: $("#op_mzfs option:selected").text() == "请选择" ? "" : $("#op_mzfs option:selected").text(),
			MZYS: $("#op_mzys").attr("data-StaffGh"),
			MZYSMC: $("#op_mzys").val(),
			QKYHLB: $("#op_yhlb").val(),
			QKYHDJ: QKYHDJ_val,
			SSLX: $("#SSLX").val(),
			SSKSSJ: $("#SSKSSJ").val(),
			SSJSSJ: $("#SSJSSJ").val(),
			SQZBSJT: $("#SQZBSJT").val(),
			SQYFKJGYS: $("#SQYFKJGYS").val(),
			MZKSSJNYR: $("#MZKSSJNYR").val(),
			MZFJ_ASA: $("#MZFJ_ASA").val(),
			QKBW: $("#QKBW").val(),
			SSQKGR: $("#SSQKGR").val(),
			SSBFZ: $("#SSBFZ").val(),
            SSBFZMC: check_val,
		};
	}


	function deletejq() {
		$("#SSKSSJ").val('')
		$("#op_ssdm").val('')
		$("#op_zdys").val('')
		$("#op_sszl1").val('')
		$("#op_sszl2").val('')
		$("#op_yhdj").val('')
		$("#op_mzfs").val('')
		$("#op_mzys").val('')
		$("#op_yhlb").val('')
		$("#SSLX").val('')
		$("#SSKSSJ").val('')
		$("#SSJSSJ").val('')
		$("#SQZBSJT").val('')
		$("#SQYFKJGYS").val('')
		$("#MZKSSJNYR").val('')
		$("#MZFJ_ASA").val('')
		$("#QKBW").val('')
		$("#SSQKGR").val('')
		$("#SSBFZ").val('')
		$("#SSJB").val('')
		deleteCheck()
	}

	$(function () {
		$(".dv-left").toggle();
		$("#sscz").click(function () {
			$(".dv-left").toggle();
		});
		$("#btn_submit_op").click(function () {
			debugger
			getCheck_val();
			getopdata();
			var hzjbxx = getfromPara();
			if (!!!opdata.SSJCZBM) {
				$.modalAlert("请选择手术项目", 'error');
				return false;
			}
			if (!!!opdata.SZ) {
				$.modalAlert("请选择主刀医生", 'error');
				return false;
			}
			if (!!!opdata.SSJCZRQ) {
				$.modalAlert("请选择手术及操作日期", 'error');
				return false;
			}
			//if (!!!opdata.SSKSSJ) {
			//	$.modalAlert("请选择手术开始日期", 'error');
			//	return false;
			//}
			//if (!!!opdata.SSJSSJ) {
			//	$.modalAlert("请选择手术结束日期", 'error');
			//	return false;
			//}

            //去除术前准备天数的空格
            SQZBSJT = opdata.SQZBSJT.replace(/^\s+|\s+$/g, '');
            SQYFKJGYS = opdata.SQYFKJGYS.replace(/^\s+|\s+$/g, '');

            if (!!SQZBSJT || !!SQYFKJGYS) {
                debugger;
				if (!!!SQZBSJT) {
					$.modalAlert("术前抗菌药物时间给定，术前准备天数则为必填", 'error');
					return false;
				}
				if (!!!SQYFKJGYS) {
					$.modalAlert("术前准备天数给定，术前抗菌药物时间则为必填", 'error');
					return false;
				}
			}

			if (!!opdata.MZYS || !!opdata.MZFS || !!opdata.MZFJ_ASA || !!opdata.MZKSSJNYR) {

				if (!!!opdata.MZYS) {
					$.modalAlert("麻醉医生为必填项", 'error');
					return false;
				}
				if (!!!opdata.MZFS) {
					$.modalAlert("麻醉方式为必填项", 'error');
					return false;
				}
				if (!!!opdata.MZFJ_ASA) {
					$.modalAlert("麻醉等级为必填项", 'error');
					return false;
				}
				if (!!!opdata.MZKSSJNYR) {
					$.modalAlert("麻醉开始时间为必填项", 'error');
					return false;
				}
			}

			if (!!opdata.QKBW || !!opdata.QKYHDJ || !!opdata.QKYHLB) {

				if (!!!opdata.QKBW) {
					$.modalAlert("切口部位为必填项", 'error');
					return false;
				}
				if (!!!opdata.QKYHDJ) {
					$.modalAlert("切口愈合等级为必填项", 'error');
					return false;
				}
				if (!!!opdata.QKYHLB) {
					$.modalAlert("切口愈合类别为必填项", 'error');
					return false;
				}
			}

            if ((!!opdata.SSBFZ && opdata.SSBFZ != 2) || !!opdata.SSBFZMC) {
				if (!!!opdata.SSBFZ) {
					$.modalAlert("并发症名称给定，手术并发症则为必填", 'error');
					return false;
				}
				if (!!!opdata.SSBFZMC) {
					$.modalAlert("手术并发症给定，并发症名称则为必填", 'error');
					return false;
				}
			}

			if (time_sjc(hzjbxx.RYSJ) > time_sjc(opdata.SSKSSJ) || time_sjc(hzjbxx.CYSJ) < time_sjc(opdata.SSKSSJ)) {
				$.modalAlert("手术开始日期不能小于入院日期且不能大于出院日期", 'warning');
				return false;
			}
			if (time_sjc(opdata.SSJSSJ) < time_sjc(opdata.SSKSSJ) || time_sjc(hzjbxx.CYSJ) < time_sjc(opdata.SSJSSJ)) {
				$.modalAlert("手术结束日期不能小于手术开始日期且不能大于出院日期", 'warning');
				return false;
			}
			if (!!opdata.SSJCZBM) {
				if (time_sjc(opdata.MZKSSJNYR) < time_sjc(opdata.SSKSSJ) || time_sjc(opdata.MZKSSJNYR) > time_sjc(opdata.SSJSSJ)) {
					$.modalAlert("麻醉开始日期不能小于手术开始日期且不能大于手术结束日期", 'warning');
					return false;
				}
			}

			if (opdata.SSJCZBM != null && opdata.SSJCZBM != undefined && opdata.SSJCZBM != "") {
				var $grid = $("#gridopList");
				var gridids = $grid.jqGrid('getDataIDs');
				//在行号序列中获取最大的编号
				var maxRowId = 0;
				if (gridids.length > 0) {
					maxRowId = Math.max.apply(Math, $grid.jqGrid('getDataIDs'));
				}

				var rowid = $("#op_rowid").val(); //是否属于修改诊断
				if (rowid != null && rowid != undefined && rowid != "" && parseInt(rowid) > 0) {
					var rowdata = $grid.jqGrid("getRowData", rowid);
					if (opdata.SSJCZBM == rowdata.SSJCZBM) {
						$grid.jqGrid("setRowData", rowid, opdata);
						$.modalAlert("录入成功", 'success');
						deletejq() 
						return true;
					}
				}

				var result = checkSSdm(opdata);
				if (result) {
					$grid.jqGrid("addRowData", maxRowId + 1, opdata);
					$("#op_rowid").val(maxRowId + 1);
					deletejq() 
				}
				else {
					$.modalAlert("手术已录入", 'error');
				}

			}
			else {
				$.modalAlert("请选择手术", 'warning');
			}

		});

		$("#btn_del_op").click(function () {
			var rowid = $("#op_rowid").val();
			if (rowid != null && rowid != undefined && rowid != "" && parseInt($("#op_rowid").val()) > 0) {
				//getopdata();
				opdata.zt = 0;
				opdata.ztsm = '作废';
				jQuery("#gridopList").jqGrid("setRowData", rowid, opdata);
				$.modalAlert("作废成功", 'success');
			}
			else {
				$.modalAlert("请选择手术记录", 'warning');
			}
		});

		$("#btn_reset_op").click(function () {
			jQuery("#gridopList").jqGrid().trigger('reloadGrid');
		});

	});

	//把time装换成时间戳，方便比较
	function time_sjc(time) {
		return new Date(time.replace(/-/g, "\/"));
	}


	function deleteCheck() {
		$("input[type='checkbox']").prop("checked", false);
	}

	function getCheck_val() {
		check_val = ''
		var obj = document.getElementsByName("SSBFZMC");
		for (k in obj) {
			if (obj[k].checked) {
				if (check_val == '') {
					check_val = obj[k].value
				} else {
					check_val = check_val + ',' + obj[k].value
				}
			}
		}
	}

	//$(function () {
	//    $("#tb_opedit").css("height","350px");
	//});

	$("#op_ssdm").opFloatingSelector({
		width: 600,
		itemdbclickhandler: function ($this) {
			$("#op_ssdm").val($this.attr('data-ssmc')).attr("attr-ssdm", $this.attr('data-ssdm')).attr("attr-ssjb", $this.attr('data-ssjb').attr("attr-ssdm", $this.attr('data-ssdm')));
		}
	});

	$("#op_zdys").dutyStaffFloatingSelector({
		dutyCode: 'Doctor'
	});
	$("#op_mzys").dutyStaffFloatingSelector({
		dutyCode: 'Doctor'
	});
	$("#op_sszl1").dutyStaffFloatingSelector({
		dutyCode: 'Doctor'
	});
	$("#op_sszl2").dutyStaffFloatingSelector({
		dutyCode: 'Doctor'
	});

	$("#op_mzfs").bindSelect({
		url: "/SystemManage/Common/GetAnesList",
		id: "AnesCode",
		text: "AnesName"
	});

	$("#op_yhdj").bindSelect({
		url: "/SystemManage/Common/GetNotchGradeList",
		id: "Code",
		text: "Name"
	});

	$("#op_yhlb").bindSelect({
		url: "/SystemManage/Common/GetCommonList",
		id: "Code",
		text: "Name",
		param: { type: "QKYLB" }
	});

	function checkSSdm(data) {
		var isadd = true;
		var ids = $("#gridopList").getDataIDs();
		if (ids.length > 1) {
			$(ids).each(function (i) {
				var rows = $("#gridopList").getRowData(i + 1);
				if (rows.SSJCZBM == data.SSJCZBM) {
					isadd = false;
				}
			})
		}
		return isadd;
	}
</script>
